<?php

class Webmix_Model_Musicalbum extends Core_Model_Item_Abstract {


  public function getPhotoUrl($type = null)
  {
    if( empty($this->photo_id) ) {
      $photoTable = Engine_Api::_()->getItemTable('webmix_musicalbum');
      $photoInfo = $photoTable->select()
          ->from($photoTable, array('photo_id', 'photo_id'))
          ->where('musicalbum_id = ?', $this->musicalbum_id)
          ->limit(1)
          ->query()
          ->fetch();
      if( !empty($photoInfo) ) {
        $this->photo_id = $photo_id = $photoInfo['photo_id'];
        $this->save();
        $file_id = $photoInfo['photo_id'];
      } else {
        return;
      }
    } else {
      $photoTable = Engine_Api::_()->getItemTable('webmix_musicalbum');
      $file_id = $photoTable->select()
          ->from($photoTable, 'photo_id')
          ->where('musicalbum_id = ?', $this->musicalbum_id)
          ->query()
          ->fetchColumn();
    }

    if( !$file_id ) {
      return;
    }

    $file = Engine_Api::_()->getItemTable('storage_file')->getFile($file_id, $type);
    if( !$file ) {
      return;
    }

    return $file->map();
  }
  public function getCountry(){
	return Engine_Api::_()->getItem('webmix_musicalbum', $this->musicalbum_id);
  }
  
    public function getHref() {
        return Zend_Controller_Front::getInstance()->getRouter()
            ->assemble(array( 
          'controller' => 'album',
          'action' => 'edit',
          'album' => $this->getIdentity()), 'webmix_general', true);
    }  
}